﻿Namespace Web
    Partial Public Class ThingToDo
        Public Property UrgenciaItem As Urgencia
            Get
                Return (From u As Urgencia In Contexte.Urgencies Where u.Id = Me.Urgencia).FirstOrDefault
            End Get
            Set(value As Urgencia)
                Urgencia = value.Id
                RaisePropertyChanged("UrgenciaItem")
            End Set
        End Property

        Public Property RealizadaItem As OpcioCombo
            Get
                Dim Id As Integer = IIf(Realizada, 1, 0)
                Return (From o As OpcioCombo In OpcionsComboSiNo.Llista Where o.Id = Id).FirstOrDefault
            End Get
            Set(value As OpcioCombo)
                If value.Id = -1 Then
                    Throw New ArgumentException()
                Else
                    Realizada = IIf(value.Id = 0, False, True)
                    RaisePropertyChanged("RealizadaItem")
                End If

            End Set
        End Property

        Public Property strData As String
            Get
                Return Right("00" & Data.Day, 2) & "/" & Right("00" & Data.Month, 2) & "/" & Right("0000" & Data.Year, 4)
            End Get
            Set(value As String)
                Try
                    Data = Date.Parse(value)
                    RaisePropertyChanged("strData")
                Catch ex As Exception
                    Throw New FormatException()
                End Try
            End Set
        End Property

        Private Sub OnUrgenciaChanged()
            RaisePropertyChanged("UrgenciaItem")
        End Sub

        Private Sub OnDataChanged()
            RaisePropertyChanged("strData")
        End Sub

        Private Sub OnRealizadaChanged()
            RaisePropertyChanged("RealizadaItem")
        End Sub
    End Class
End Namespace